package com.gl.codewar.template;

public class HappyNumbers {

	public static boolean isHappy(int i) {
	
            int loops = 0;
            int sum;
            int num = i;
            do {
                sum = 0;
                String number = Integer.toString(num);
                int[] digits = new int[number.length()];
                for(int d = 0; d < digits.length; d++) {
                   digits[d] = Integer.valueOf(number.substring(d,d+1));
                   digits[d] = digits[d] * digits[d];
                }
                for(int d = 0; d < digits.length; d++) { 
                    sum += digits[d];
                }
                num = sum;
                 loops++;
            }while( num > 1 && loops < 100);
            
            if ( sum == 1 ) {
                return true;
            }
            
            return false;
       
	}

}
